package user.ucm;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import user.model.AirVModel;
import user.model.UserModel;

public class UCRegistering {

    private UserModel um;

    public UCRegistering() {
    }

    public UCRegistering(UserModel um) {
        this.um = um;
    }

    public int run() {
        try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/cp3120?user=root&password=root");
            con.setCatalog("cp3120");

            Statement statement = con.createStatement();
            String sql = "INSERT INTO userinfo VALUES(" +
                    "'" + um.getName() + "','" + um.getPsw() + "'," + um.getAge() + ",'" + um.getActure_name() + "',0,0)";
            System.out.println(sql);
            statement.execute(sql);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    public int adminrun() {
        try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/cp3120?user=root&password=root");
            con.setCatalog("cp3120");

            Statement statement = con.createStatement();
            String sql = "INSERT INTO userInfo VALUES(" +
                    "'" + um.getName() + "','" + um.getPsw() + "'," + um.getAge() + ",'" + um.getActure_name() + "',0,1)";
            System.out.println(sql);
            statement.execute(sql);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    public int managerrun(AirVModel avm) {
        try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/cp3120?user=root&password=root");
            con.setCatalog("cp3120");

            Statement statement = con.createStatement();
            String sql = "INSERT INTO airinfo VALUES(" +
                    "'" + avm.getAirName_TextField().getText() + "','" + avm.getPrice_TextField().getText() +
                    "','" + avm.getDestination_TextField().getText() + "','" + avm.getSetOut_TextField().getText() + "')";
            System.out.println(sql);
            statement.execute(sql);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
}
